﻿#pragma once
namespace LK
{
	struct ICloneables :virtual Object
	{
		typedef ptr<ICloneables> PObj;
		typedef ICloneables IObj;
		/*动态获取类型信息*/
		virtual ptr<Type> GetType()const;
		/*operator&重载*/
		IObj*operator&() { Object::operator&(); return this; }
		IObj const*operator&()const { Object::operator&(); return this; }
		virtual void SwapWith(Object&) { Throw<PNotSupportException >(); }
		/**@brief 获取该对象的浅表副本*/
		virtual ICloneables* Clone()const = 0;
		/**
		@brif 添加类型信息*/
		static void AddTypeInfo();
		/**@brief 检查对象引用计数如果不为1，则改变r为Clone的引用。空引用将抛出异常*/
		static ptr<Object>& OnePtr(PObject&r) { if (r.UseCount != 1) { r=CastPointer<ICloneables>(r.GetPtr())->Clone(); } return r; }
	};
	PTRPREDEFINE(,ICloneables)
}